package com.yanqu.road.server.cmd.activity.peakstronghold;

import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongHoldConfig;
import com.yanqu.road.entity.activity.peakstronghold.config.ePeakStrongholdStageType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakStrongholdWarProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.peakstronghold.PeakStrongholdActivityMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_PEAK_STRONGHOLD_ELIMINATION_UNION_DATA, desc = "获取淘汰赛联盟据点情况")
public class PeakStrongholdUnionDataCmd extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (null == player) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        PeakStrongHoldConfig config = PeakStrongholdActivityMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

//        if (!PeakStrongholdActivityMgr.canUnionInBattle(player.getUserInfo().getUnionUid())) {
//            ret = GameErrorCode.E_PEAK_HOLD_NOT_IN_ELIMINATE;
//            return;
//        }
        if (config.getStageType() != ePeakStrongholdStageType.Prepare && config.getStageType() != ePeakStrongholdStageType.InBattle) {
            ret = GameErrorCode.E_PEAK_HOLD_NOT_IN_ELIMINATE;
            return;
        }
        PeakStrongholdWarProto.GetPeakEliminateUnionListReqMsg reqMsg = PeakStrongholdWarProto.GetPeakEliminateUnionListReqMsg.parseFrom(packet.getBytes());
        PeakStrongholdWarProto.CrossPeakHoldMemberSilverDonateReq.Builder crossMsg = PeakStrongholdWarProto.CrossPeakHoldMemberSilverDonateReq.newBuilder();
        crossMsg.setActivityId(config.getActivityInfo().getActivityId());
        String ownUnionUid = GameUnionActivityGroupMgr.getUnionUid(crossMsg.getActivityId(), player.getUserId());
        crossMsg.setUnionId(ownUnionUid);
        crossMsg.setGroup(reqMsg.getGroup());
        player.sendUnionActivityGroupPacket(Protocol.C_PEAK_STRONGHOLD_ELIMINATION_UNION_DATA, crossMsg, crossMsg.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
